HTMLify
index.html
Views: 403 | Author: cody
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Clock</title> <link rel="stylesheet" href="style.css" /> <link rel="icon" href="assets/favicon.png"> </head> <body> <h2 class="heading"> Clock </h2> <div class="clock"> <div class="hour"> <div class="hr" id="hr"></div> </div> <div class="min"> <div class="mn" id="mn"></div> </div> <div class="sec"> <div class="sc" id="sc"></div> </div> </div> <footer> <p>< / > with ❤️ by <a href="https://swapnilsparsh.github.io/">Swapnil Srivastava</a> <br> <a href="https://github.com/swapnilsparsh/30DaysOfJavaScript" target="_blank">#30DaysOfJavaScript </a> </p> </footer> <script type="text/javascript"> const deg = 6; // getting all hands of clock from html through id const hr = document.querySelector('#hr') const mn = document.querySelector('#mn'); const sc = document.querySelector('#sc'); setInterval(() => { let day = new Date(); //setting the actual seconds minutes and hour in clock let ms = day.getMilliseconds() * deg; let hh = day.getHours() * 30; let mm = day.getMinutes() * deg; let ss = day.getSeconds() * deg + ms / 1000; //changing the degrees in the style as per the time hr.style.transform = `rotateZ(${(hh) + (mm / 12)}deg)`; mn.style.transform = `rotateZ(${mm}deg)`; sc.style.transform = `rotateZ(${ss}deg)`; }, 1); </script> </body> </html> |